﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;

namespace MainConsole
{
    class ConfigHandler:IConfigurationSectionHandler
    {
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            ObjectInfo info;
            PropertyInfo propInfo;
            ConfigInfo cfgInfo = new ConfigInfo();
            foreach (XmlNode node in section.ChildNodes)
            {
                info = new ObjectInfo();
                info.name = node.Attributes["name"].Value;
                info.assemblyName = node.Attributes["assembly"].Value;
                info.typeName = node.Attributes["typeName"].Value;
                foreach (XmlNode prop in node)
                {
                    propInfo = new PropertyInfo();
                    propInfo.propertyName = prop.Attributes["name"].Value;
                    propInfo.assemblyName = prop.Attributes["assembly"].Value;
                    propInfo.typeName = prop.Attributes["typeName"].Value;
                    info.properties.Add(propInfo);
                }
                cfgInfo.Objects.Add(info);
            }
            return cfgInfo;
        }
    }

   
}
